package com.liuxia8.part7.delegation;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by weng.junjie on 2017/2/18.
 */
public class SpaceShip extends SpaceShipControls {
    private String name;

    public SpaceShip(String name) {
        this.name = name;
    }

    public String toString() {
        System.out.println("toString init");
        return name;
    }

    public String setName(String name) {
        System.out.println(name);
        this.name = name;
        return name;
    }

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        SpaceShip protector = new SpaceShip("nsea protector");
        protector.forward(100);
        Method[] m = protector.getClass().getMethods();
        Method d = protector.getClass().getMethod("setName",String.class);
        d.invoke(protector, "aa");

        d = protector.getClass().getMethod("toString");
        d.invoke(protector);
    }
}
